<?php
$name = isset($_POST['name']) ? $_POST['name'] : '';
$company = isset($_POST['company']) ? $_POST['company'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';

$correct = strlen($name) > 0 && strlen($company) > 0 && preg_match('/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/', $email) > 0;

if ($correct) {

    $to = 'info@biyond.nl';
    $subject = 'Gegevens van download';
    $message = 'Naam: ' . $name . "\r\n" .
            'Bedrijf: ' . $company . "\r\n" .
            'Email: ' . $email;
    $headers = 'From: download@biyond.nl' . "\r\n" .
            'Reply-To: info@biyond.nl' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

    $res = mail($to, $subject, $message, $headers);

    header('Content-type: application/pdf');
    header('Content-Disposition: attachment; filename="biyond' . ($res ? '1' : '0') . '.pdf"');
    readfile('./biyond.pdf');
} else {
    include('./header.html');
?>
    <div class="articletitle">Download formulier <img src="./style/img/download.gif" alt="home"></div>
    <div class="articlecontent">
        <form action="pdfdownload.php" name="pdfdownload" id="pdfdownload" method="POST" onsubmit="return checkForm();">
            <fieldset>
                <legend style="color: red;">Alle velden zijn verplicht.</legend>
                <label for="name">
                    <span class="labelText">Naam</span>
                    <input type="text" name="name" id="name">
                </label>
                <label for="company">
                    <span class="labelText">Bedrijf</span>
                    <input type="text" name="company" id="company">
                </label>
                <label for="email">
                    <span class="labelText">Email</span>
                    <input type="text" name="email" id="email">
                </label>
                <input class="submit" type="submit" name="submit" value="Download">
            </fieldset>
        </form>
    </div>
<?php
    include('./footer.html');
}
?>